package com.star.demo.biz;

import com.star.common.core.utils.BeanKit;
import com.star.demo.contract.command.DemoDeleteCommand;
import com.star.demo.contract.command.DemoImportExcelCommand;
import com.star.demo.contract.command.DemoSaveCommand;
import com.star.demo.contract.command.DemoUpdateCommand;
import com.star.demo.repository.model.DemoBO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author zhouhengzhe
 * @Desc Demo仓库，主要是给人去学习用(Demo)表领域处理服务类，用于demo领域的增删改领域
 * @Date 2023-12-01 17:25:30
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class DemoService {

    /**
     * 保存demo
     *
     * @param demoSaveCommand demo请求体
     */
    public void save(DemoSaveCommand demoSaveCommand) {
        BeanKit.copy(demoSaveCommand, DemoBO.class).save();
    }

    /**
     * 删除demo
     *
     * @param demoDeleteCommand 删除请求体
     */
    public void removeDemo(DemoDeleteCommand demoDeleteCommand) {
        DemoBO.repository().delete(demoDeleteCommand.getId());
    }

    /**
     * 更新demo
     * @param demoUpdateCommand 更新请求体
     */
    public void updateDemo(DemoUpdateCommand demoUpdateCommand) {
        BeanKit.copy(demoUpdateCommand, DemoBO.class).update();
    }

    /**
     * 上传demo
     * @param dataList demo列表
     */
    public void uploadDemo(List<DemoImportExcelCommand> dataList) {
        List<DemoBO> demoBos = dataList.stream()
                .map(data -> BeanKit.copy(data, DemoBO.class))
                .toList();
        DemoBO.repository().save(demoBos);
    }
}
